home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3291 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.5 KB

  1. Path: Rezonet.net!news
  2. From: ray@ultimate-tech.com (Ray Dunn)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Q: Getting data from a FAR CHAR * buffer: HELP!
  5. Date: 25 Jan 1996 16:09:15 GMT
  6. Organization: Ultimate Technographics Inc.
  7. Message-ID: <4e89vc$ehg@ns.RezoNet.NET>
  8. References: <4e7208$iqb@dingo.cc.uq.oz.au>
  9. NNTP-Posting-Host: 204.19.230.7
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=US-ASCII
  12. X-Newsreader: WinVN 0.99.7
  13.  
  14. In referenced article, coonsta@peg.apc.org says...
  15. >
  16. >typedef struct pcx_picture_typ
  17. >{
  18. >        pcx_header header;          //Forget it: it's irrelevant
  19. >        RGB_color pallette[256];    //Forget this too.
  20. >        char far *buffer;           //That's the one.
  21. >} pcx_picture, *pcx_picture_pointer;
  22. >
  23. >Every pcx_picture is initalised with this call, which allocates memory
  24. >for the buffer.  I don't think it makes any difference, but here 'tis:
  25. >
  26. >void PCX_Init(pcx_picture_ptr image)
  27. >{
  28. >        image->buffer = (char far *)_fmalloc(64000);
  29. >}
  30. >
  31. >void main(void)
  32. >{
  33. >        int x;
  34. >        pcx_picture thepicture;
  35. >
  36. >        .    (The buffer is initialised and filled with data from a
  37. >        .     file in here).
  38. >        .
  39. >
  40. >        x = thepicture.buffer[32000];   // doesn't seem to work.
  41. >}
  42.  
  43. There doesn't seem to be anything wrong with this code fragment, so I 
  44. would suspect that your problem is perhaps in the filling of the buffer 
  45. from the file.
  46.  
  47. Test it with a text file and write a little test loop outputting each 
  48. character from the buffer.  You should see your text file getting 
  49. printed.
  50.  
  51. [system specific response warning]
  52.  
  53. In this case your problem may be with the system specific "far" 
  54. declaration.  I'm always suspicious when I see it's use, because you 
  55. only need "far" if you're compiling in small or medium model.  If that 
  56. is the case, then you cannot call read or fread with a pointer to that 
  57. far buffer because these library routine expect a near pointer in these 
  58. models (at least MSC).  Are you ignoring some compiler warnings?
  59.  
  60. If you're compiling in large model, you don't need to use "far" because 
  61. all pointers are far.  I strongly recommend that if you need to create 
  62. far data, then use large model and you can then forget about all these 
  63. issues - and it has the advantage that you can then post code without 
  64. being yelled at for using non-conforming keywords like "far"!
  65.  
  66. Further discussion of this topic should go to a DOS or Windows 
  67. newsgroup.
  68. --
  69. Ray Dunn (opinions are my own) | Phone: (514) 938 9050
  70. Montreal                       | Phax : (514) 938 5225
  71. ray@ultimate-tech.com          | Home : (514) 630 3749
  72.  
  73.